import Vue from 'vue';
//  导入vue-resource
import VueResource from 'vue-resource';
// 注册vue-resource模块
Vue.use(VueResource);
// 全局配置接口域名
Vue.http.options.root="http://www.liulongbin.top:3005"
Vue.http.options.emulateJSON=true;

//导入vue-preview
import VuePreview from 'vue-preview';
Vue.use(VuePreview);

// 导入mui的样式
import './lib/mui/css/mui.min.css';
import './lib/mui/css/icons-extra.css';


// 导入router.js
import router from './router.js'
// 导入根组件
import App from './App.vue';




// 按需导入名mint-ui
import {Header,Swipe,SwipeItem,Button} from 'mint-ui';
// 注册组件
Vue.component(Header.name, Header);
Vue.component(Swipe.name, Swipe);
Vue.component(SwipeItem.name, SwipeItem);
Vue.component(Button.name, Button);


// 定义过滤器
Vue.filter('dateFmt',(input,sep='/',flag=false)=>{
    let obj=new Date(input);
    let year=obj.getFullYear();
    let month=obj.getMonth()+1;
    let day=obj.getDate();
    if(flag){
        let hour=obj.getHours();
        let minute=obj.getMinutes();
        let second=obj.getSeconds();
        return `${year}${sep}${month}${sep}${day} ${hour}:${minute}:${second}`;
    }else{
        return `${year}${sep}${month}${sep}${day}`;
    }
   
});

// 导入moment
import moment from 'moment';
Vue.filter('dateFormat',(input,pattern="YYYY-MM-DD HH:mm:ss")=>{
    return moment(input).format(pattern)
})

// 路由守卫
router.beforeEach((to, from, next) => {

    if(to.meta.content){
        let head = document.getElementsByTagName('head');
        let meta = document.createElement('meta');
        meta.content = to.meta.content;
        head[0].appendChild(meta)
    }

    if(to.meta.title){
        document.title=to.meta.title+'-Vue-cms';
    }

    next();
})

var vm=new Vue({
    el:'#app',
    data:{
        msg:'hello vue'
    },
    router,    //挂载路由模块
    render(createElement){
        // 在页面渲染App根组件
        return createElement(App);
    }
})